﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArbolandiaBL
{
    internal abstract class PreferenceBase
    {

        protected ArbolandiaDBDataContext _db;
        protected PreferenceBase()
        {
            _db = new ArbolandiaDBDataContext();
        }
        internal virtual void InsertUpdatePreference(Product_Preference pp)
        {
            var query = _db.Product_Preference.Where(w => w.Id == pp.Id);
            if (query.Count() <= 0)
            {
                _db.Product_Preference.InsertOnSubmit(pp);
            }
            else
            {
                query.First().DefaultDescription = pp.DefaultDescription;
                query.First().IsOpenText = pp.IsOpenText;
                query.First().Name = pp.Name;
                query.First().Options = pp.Options;
            }
            _db.SubmitChanges();

        }
        internal virtual void DeletePreference(int preferenceid)
        {
            var query = _db.Product_Preference.Where(w => w.Id == preferenceid);
            if (query.Count() > 0)
            {
                _db.Product_Preference.DeleteOnSubmit(query.First());
                _db.SubmitChanges();
            }
        }
    }
}
